home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / pcdbms.arc / MANUAL.2 < prev    next >
Text File  |  1985-09-13  |  55KB  |  2,444 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                         CHAPTER 5
  16.  
  17.                     COMMAND REFERENCE
  18.  
  19.  
  20.  
  21. OVERVIEW
  22.  
  23. The commands summarized in Table 5-1 are  implemented  in
  24. PC-DBMS.  Subsequent sections document them.
  25.  
  26. COMMAND         FUNCTION    
  27.  
  28. DEFINE          invokes define utility to update schema
  29. DEKEY           removes an index
  30. DISPLAY         invokes display utility to update 
  31.                     a table
  32. EXIT            terminates execution of PC-DBMS
  33. KEY             builds an index
  34. OPEN            makes available an existing or new 
  35.                     data base
  36. OUTPUT          redirects output to file or printer
  37. REMOVE          removes table from the data base
  38. SELECT          retrieves records from one or two tables
  39. SHOW            displays portion of schema
  40. TOLERANCE       sets tolerance used for numeric 
  41.                     comparisons
  42.  
  43. Table 5-1.  Summary of PC-DBMS commands.
  44.  
  45.  
  46.  
  47.  
  48.  
  49.                            5-1
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.                     COMMAND REFERENCE
  70.                  NOTATIONAL CONVENTIONS
  71.  
  72.  
  73. NOTATIONAL CONVENTIONS
  74.  
  75. Syntax  forms  for  the  commands   use   the   following
  76. notational conventions.
  77.  
  78.       -  Lower  case  words  indicate  that  you   should
  79.          substitute a word or value of your choice.
  80.  
  81.       -  Upper case words are keywords and they should be
  82.          used  where  shown.   However,  keywords  can be
  83.          truncated to three or more characters and can be
  84.          entered in upper or lower case.
  85.  
  86.       -  Brackets ([]) indicate optional elements.
  87.  
  88.       -  Ellipses (...) indicate  the  preceding  item(s)
  89.          may be repeated one or more times.
  90.  
  91.  
  92.  
  93.  
  94. DEFINE
  95.  
  96. The define command is issued after the  open  command  is
  97. given  for  a  new or existing data base.  It invokes the
  98. define utility to enter definitions of tables  and  their
  99. fields.  The syntax is:
  100.  
  101.      DEFINE
  102.  
  103. The define utility is conversational.   It  presents  two
  104. data   entry  screens.   The  first  screen  accepts  the
  105. description  of  a  table.   The  second  screen  accepts
  106. descriptions of that table's fields.
  107.  
  108. The first or table screen prompts for the  table's  name,
  109. the  specification  of the file containing it, the record
  110. termination character and an optional verbal description.
  111.  
  112.  
  113.  
  114.  
  115.                            5-2
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.                     COMMAND REFERENCE
  136.                          DEFINE
  137.  
  138.  
  139. When that screen is completed,  the  second  screen  type
  140. appears for entry of field data -- field name, data type,
  141. field width, indexing and an optional verbal description.
  142. When completed, the screen reappears blank for definition
  143. of the next field.  If there is no  "next"  field,  press
  144. F10  and  the  first  data  entry screen will reappear to
  145. define the next table.   Then,  if  there  is  no  "next"
  146. table, press F10 to exit the define utility.
  147.  
  148. File specifications may not include path names but  drive
  149. names  may  be  used.  If a drive name is given, the file
  150. must always be on that disk drive.  If no drive  name  is
  151. given,  the  file  must  be on the logged (default) drive
  152. which you can set at the DOS level.
  153.  
  154. The table screen prompts for a number to describe the end
  155. of  record  terminator.  Enter 0 for no terminator, 1 for
  156. carriage return and 2 for carriage return-line feed.  The
  157. choice  of  2  facilitates  processing  the  file outside
  158. PC-DBMS.
  159.  
  160. Fields may have one of three data types:  text, number or
  161. filler.   Filler  fields  may contain anything -- blanks,
  162. numbers  or   text.    The   indexing   and   description
  163. information  is  not solicited for filler fields.  Filler
  164. fields can be displayed with the select command  but  may
  165. not  be  used  in  where  or  sort  clauses.  The display
  166. utility ignores them;  on input, they are  blank  filled.
  167. Filler fields are useful in masking columns of extraneous
  168. material in imported files or to  insert  blanks  between
  169. fields during input.
  170.  
  171. If a field is more than 141 characters wide, it cannot be
  172. indexed so the index prompt will not appear.
  173.  
  174. If the data base is to include a  table  in  an  imported
  175. file,  its  definition  must  exactly  describe the file.
  176. Filler fields of any desired  width  can  be  used.   Any
  177. record  whose  first character is a backslash (\) will be
  178. considered deleted.
  179.  
  180.  
  181.                            5-3
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.                     COMMAND REFERENCE
  202.                           DEKEY
  203.  
  204.  
  205. DEKEY
  206.  
  207. The dekey command updates the schema so that it shows the
  208. named  field as not keyed.  It has no effect on the index
  209. file but the old index will never be usable.  The  syntax
  210. is:
  211.  
  212.      DEKEY qfn
  213.  
  214. Qfn is  a  qualified  field  name.   For  example,  DEKEY
  215. OPUS.WORK  changes the schema so that field WORK in table
  216. OPUS is regarded as not keyed.  When a field is  indexed,
  217. it  is necessary to maintain the indices when records are
  218. added,  changed  or  deleted.    Dekeying   avoids   this
  219. overhead.
  220.  
  221.  
  222.  
  223. DISPLAY
  224.  
  225. The display command projects a data  entry  form  on  the
  226. screen.   The  form consists of background text and field
  227. blocks corresponding to non-filler  fields  in  the  data
  228. table.  The syntax is:
  229.  
  230. DISPLAY [\INPUT] table_name [WHERE    ]
  231.          \QUERY
  232.          \EDIT
  233.  
  234. The display form operates on  a  single  table  given  by
  235. table_name.   That  table may have up to 60 fields.  Some
  236. tables may  be  rejected  because  all  their  non-filler
  237. fields cannot be squeezed onto the screen.
  238.  
  239. A form  will  be  created  dynamically.   Display  fields
  240. corresponding   to  data  fields  appear  as  rectangular
  241. blocks;  they are one or more characters wide and one  or
  242. more lines high.
  243.  
  244.  
  245.  
  246.  
  247.                            5-4
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.                     COMMAND REFERENCE
  268.                          DISPLAY
  269.  
  270.  
  271. The display command has  four  forms.   With  the  \QUERY
  272. qualifier,  a  select  command is composed for use as the
  273. next command.  If \INPUT is specified,  new  records  are
  274. entered  and  appended  to  the table.  The default \EDIT
  275. qualifier permits  retrieval,  editing  and  deletion  of
  276. existing  records.   The where clause form of the command
  277. also retrieves records for editing  and  deletion,  those
  278. satisfying  the where clause.  Screen layouts are similar
  279. for all forms;  only the bottom information lines differ.
  280. The various forms are discussed below.
  281.  
  282. An example of the \INPUT form is
  283.  
  284.      DISPLAY\INPUT COMP
  285.  
  286. In this example, a form will be projected  with  a  blank
  287. field  for  each non-filler data field in the COMP table.
  288. Next to each field, its  name  will  be  shown.   At  the
  289. bottom  right  of  the screen, INPUT will be displayed to
  290. identify the function.  The rest of the bottom line gives
  291. other useful information.
  292.  
  293. Fill in all fields (or leave some blank) and press F7  to
  294. store  the  new  record.   The  form reappears with blank
  295. fields to enter another record.  Press F10  to  exit  the
  296. display  utility.   However,  exiting  does not store any
  297. record still on screen.
  298.  
  299. The \QUERY form of  the  display  command  helps  compose
  300. certain  select  commands.   The  form shows QUERY at the
  301. bottom right and has blank fields.  Fill in up to ten  of
  302. them  and  press  F7.  This exits the display utility and
  303. restores the main screen.   A  select  command  resulting
  304. from  the  QUERY  form  entries  will  be  in the command
  305. window.  Edit, erase or execute it.   It  will  have  AND
  306. connectives,  no parentheses, no negations, = comparisons
  307. and ALL in its display list.
  308.  
  309. For example, suppose you invoke the display utility with
  310.  
  311.      DISPLAY\QUERY COMP
  312.  
  313.                            5-5
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.                     COMMAND REFERENCE
  334.                          DISPLAY
  335.  
  336.  
  337. You enter 1770 in the BORN field and  Beethoven,  L.   in
  338. the  NAME  field.   After  pressing  F7,  the main screen
  339. reappears with the following in the command window:
  340.  
  341.      SELECT  COMP.ALL  WHERE  NAME="Beethoven,  L."   AND
  342.      BORN=1770
  343.  
  344. The command  can  be  edited  if  it's  unsuitable.   For
  345. example,  only  certain  fields  might  be desired in the
  346. output.
  347.  
  348. The \EDIT form of the display command is used to find and
  349. edit  or  delete  records.  Two phases repeat in a cycle.
  350. First, a screen query is  executed.   Second,  qualifying
  351. records are displayed one after the other on the form for
  352. editing and deletion.  When the editing and deletion  are
  353. complete,  the blank query screen reappears to repeat the
  354. process.
  355.  
  356. For example, to edit  records  in  the  COMP  table,  the
  357. command is
  358.  
  359.      DISPLAY\EDIT COMP
  360.  
  361. The query phase of the cycle is almost identical  to  the
  362. DISPLAY\QUERY function.  A form appears with QUERY at the
  363. bottom right and blank fields.  Fill in up to ten  fields
  364. and  press F7 to execute the query.  Alternatively, press
  365. F10 to exit from the display utility.
  366.  
  367. If  F7  was  pressed,  all  the  qualifying  records  are
  368. displayed  one  at  a  time on the form.  The bottom line
  369. will now show editing prompts and EDIT at the right.
  370.  
  371. As each qualifying record is displayed, do one  of  three
  372. things:   leave  it  unchanged, edit it or delete it.  To
  373. leave it unchanged, press  F7.   To  edit  it,  make  the
  374. desired  changes  on  screen and press F6.  To delete it,
  375. press F4.  In any case, the next qualifying  record  will
  376. be  displayed.   However,  to return to the first (query)
  377. phase, press F10.  It is not possible to exit the display
  378.  
  379.                            5-6
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.                     COMMAND REFERENCE
  400.                          DISPLAY
  401.  
  402.  
  403. utility directly from the edit screen.
  404.  
  405. After all qualifying records  have  been  displayed,  the
  406. screen will clear and the following message will appear:
  407.  
  408.         NO (MORE) RECORDS QUALIFY
  409.  
  410.                             Press any key to continue
  411.  
  412. After pressing a key, the query screen reappears to begin
  413. the  query-edit  cycle anew.  Alternatively, press F10 to
  414. exit the display utility.
  415.  
  416. DISPLAY\EDIT is the default.  That is,  if  there  is  no
  417. where  clause  and  no  qualifier  (\),  then  the  \EDIT
  418. qualifier is assumed.
  419.  
  420. The last form of the display command is the only one that
  421. uses  the  where clause.  Any qualifier is ignored.  This
  422. form of the command retrieves for  editing  and  deletion
  423. records which satisfy the where clause.
  424.  
  425. The where clause is documented under the select  command.
  426. The  default table name at the beginning of the clause is
  427. table_name.  A second table  can  be  referenced  in  the
  428. clause.
  429.  
  430. Qualifying records are projected on the same edit  screen
  431. used  with the \EDIT form of the command.  However, after
  432. the last record has been processed, the  display  utility
  433. is exited.
  434.  
  435. For example, one way to retrieve Beethoven's  record  for
  436. editing is with this command:
  437.  
  438.      DISPLAY COMP WHERE NAME $ "Beethoven"
  439.  
  440. When text fields  are  entered  or  displayed  on  screen
  441. forms,  quote  marks  are treated as ordinary characters;
  442. they are not string delimiters.  Hence, use one quote for
  443. each quote mark you wish to embed in the record.
  444.  
  445.                            5-7
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.                     COMMAND REFERENCE
  466.                          DISPLAY
  467.  
  468.  
  469. Numbers are entered according to the rules for numbers in
  470. commands.    See  COMMAND  FORMATTING  AND  EXECUTION  in
  471. chapter 4.
  472.  
  473. The  PC-DBMS  editor  operates  in  each   field   block.
  474. However, only replace mode is available.  See THE PC-DBMS
  475. EDITOR in chapter 4.
  476.  
  477. To move the cursor forwards from one field to  the  next,
  478. press tab.  Press F9 to move it backwards.
  479.  
  480. A help screen is available by pressing F1.
  481.  
  482. Whenever records are added, deleted or  modified  by  the
  483. display   utility,   the   corresponding  index  file  is
  484. automatically updated.  However, if more than  13  fields
  485. are  indexed,  only  the  first  13 will be updated.  The
  486. indices on the other  fields  will  be  incorrect.   They
  487. should  be dekeyed and then rebuilt with the key command.
  488. In practice, few tables have more than 13 keys.
  489.  
  490.  
  491.  
  492. EXIT
  493.  
  494. The exit command  terminates  execution  of  PC-DBMS  and
  495. returns  the user to the operating system.  The command's
  496. syntax is EXIT but it can be issued by pressing F10.
  497.  
  498.  
  499.  
  500. KEY
  501.  
  502. The key command builds an index for the  specified  field
  503. and  updates the schema to reflect that fact.  The syntax
  504. is:
  505.  
  506.      KEY qfn
  507.  
  508.  
  509.  
  510.  
  511.                            5-8
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.                     COMMAND REFERENCE
  532.                            KEY
  533.  
  534.  
  535. Qfn  is  a  qualified  field  name.   For  example,   KEY
  536. OPUS.WORK builds an index for the field WORK in the table
  537. OPUS.  The index  will  be  updated  when  the  table  is
  538. altered by the display command.
  539.  
  540. Indexing will be aborted and an error  message  displayed
  541. if  an  attempt  is  made  to  key a field wider than 141
  542. characters.
  543.  
  544.  
  545.  
  546. OPEN
  547.  
  548. Open is typically the first command the user  gives.   It
  549. makes  an existing data base available.  If the data base
  550. does not exist, its schema file  will  be  created.   The
  551. command syntax is:
  552.  
  553.      OPEN dbname
  554.  
  555. Dbname is the name of the existing or new data base.  For
  556. example, OPEN MUSIC.
  557.  
  558. There is no close command.  An open  data  base  will  be
  559. closed when the exit or open command is given.
  560.  
  561.  
  562.  
  563. OUTPUT
  564.  
  565. The output command is used to redirect the output of  the
  566. show and select commands to a file or to a device such as
  567. a printer.  The syntax is:
  568.  
  569.      OUTPUT [file-spec]
  570.  
  571. File-spec is  the  name  of  the  file  or  device.   For
  572. example,  OUTPUT FILE.DAT sends output to a disk file and
  573. OUTPUT  LPT1:    prints   the   output.    If   no   file
  574. specification  is  given,  the  screen  default  will  be
  575. restored.
  576.  
  577.                            5-9
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.                     COMMAND REFERENCE
  598.                          OUTPUT
  599.  
  600.  
  601. If file-spec is a disk file which already exists, it will
  602. be deleted and a new file of the same name created.
  603.  
  604. The redirected output will include  column  headings.   A
  605. file  created by this command will not become part of the
  606. data base.  That function is served by the "into"  clause
  607. of the select command.
  608.  
  609.  
  610.  
  611. REMOVE
  612.  
  613. The remove command marks as deleted the schema definition
  614. of the named table(s).  The syntax is:
  615.  
  616.      REMOVE table_name [...]
  617.  
  618. For example, REMOVE CUSTOMERS BALANCES  removes  the  two
  619. named  tables.   The  data  files  are unaffected by this
  620. command but they can no longer be accessed.
  621.  
  622.  
  623.  
  624. SELECT
  625.  
  626. The select command retrieves data from the tables.  It is
  627. capable  of  gathering  data  from  one  or  two  tables,
  628. filtering and sorting the retrieved  records,  displaying
  629. up  to  12  of their fields in any order, and writing the
  630. result to a new table which becomes a part  of  the  data
  631. base.   The  output  ordinarily  is written to the bottom
  632. half of the screen or whatever target is specified by the
  633. output  command.   However, output will be written to the
  634. designated new table if the into clause is used.
  635.  
  636. The abbreviated syntax is:
  637.  
  638.      SELECT qfn's [WHERE    ] [SORTED BY    ]
  639.         [INTO new_table_name]
  640.  
  641.  
  642.  
  643.                           5-10
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.                     COMMAND REFERENCE
  664.                          SELECT
  665.  
  666.  
  667. The first clause, qfn's, is the only necessary  one.   It
  668. is  a list of qualified field names to be displayed.  The
  669. fields can come from one or two tables.  An example of  a
  670. two   table   retrieval  is  SELECT  COMP.NAME  COMP.BORN
  671. OPUS.WORK.  If more than  twelve  fields  are  specified,
  672. additional  ones  will  be  ignored and the query will be
  673. executed.  The display will be truncated  to  accommodate
  674. screen width.
  675.  
  676. To display all fields of a table, two special  qfn's  can
  677. be  used.  The table name and period are as usual but the
  678. field name is either ALL or ALLF.   For  example,  SELECT
  679. COMP.ALL  displays  all  non-filler  fields  of  the COMP
  680. table.  ALLF is used when  the  filler  fields  are  also
  681. desired.
  682.  
  683. Each time a table name is encountered (in  a  qfn),  that
  684. table  becomes the default.  Subsequent field names which
  685. omit the table name  and  period  reference  the  default
  686. table.   For  example,  SELECT COMP.NAME COUNTRY OPUS.ALL
  687. displays two fields from COMP and all fields from OPUS.
  688.  
  689. Figure 5-1 is an example of a simple select command.
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.                           5-11
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.                     COMMAND REFERENCE
  730.                          SELECT
  731.  
  732.  
  733.  
  734.         SELECT COMP.ALL
  735.  
  736.  
  737. NAME                 BORN  DIED  COUNTRY          
  738.  
  739. Tchaikovsky, P.      1840  1893  Russia         
  740. Brahms, J.           1833  1897  Germany        
  741. Verdi, G.            1813  1901  Italy          
  742. Handel, G.           1685  1759  England        
  743. Mozart, W.           1756  1791  Austria        
  744. Bach, J.             1685  1750  Germany        
  745. Chopin, F.           1810  1849  France         
  746. Beethoven, L.        1770  1827  Germany        
  747. Haydn, F.            1732  1809  Austria        
  748. Mendelssohn, F.      1809  1847  Germany        
  749. Debussy, C.          1862  1918  France         
  750.  
  751. Figure 5-1.  A simple select command.
  752.  
  753. The where clause is optional.  A  where  clause  contains
  754. one to ten comparisons (conditions) connected by ANDs and
  755. ORs.  A record  must  satisfy  the  where  clause  to  be
  756. displayed.  For example, attaching the where clause WHERE
  757. BORN>1799 to the preceding query would eliminate from the
  758. display the five composers born before 1800.
  759.  
  760. The eight comparisons are shown in Table 5-2.
  761.  
  762.         COMPARISON                REPRESENTATION
  763.  
  764.         less than                       <
  765.         less than or equal to           <=
  766.         equal to                        =
  767.         greater than or equal to        >=
  768.         greater than                    >
  769.         unequal to                      <>
  770.         contains                        $
  771.         does not contain                %
  772.  
  773. Table 5-2.  The eight comparison operators.
  774.  
  775.                           5-12
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.                     COMMAND REFERENCE
  796.                          SELECT
  797.  
  798.  
  799. On one side of the comparison there must be a field name,
  800. possibly  qualified.   On  the  other  side, there may be
  801. another field name, possibly qualified,  or  a  constant,
  802. numeric  or text as appropriate.  The elements on the two
  803. sides of the comparison must be of the  same  data  type,
  804. both numeric or both text.  Filler fields may not be used
  805. in comparisons.  All eight operators  can  be  used  with
  806. text  elements.   Only  the  first  six  can be used with
  807. numeric elements.  Spaces before and after  the  operator
  808. are optional.
  809.  
  810. For numeric comparisons, the default tolerance  is  zero.
  811. The tolerance can be altered with the tolerance command.
  812.  
  813. Text  constants  used  with  the  first  six   comparison
  814. operators  are  right  padded  with  blanks  to match the
  815. length of the field element on  the  other  side  of  the
  816. comparison.   If a text constant is longer than the field
  817. element, the query will be  rejected.   Text  comparisons
  818. use  the ASCII collating sequence.  Hence, WHERE NAME>"B"
  819. excludes NAMEs beginning with "A".
  820.  
  821. The $ and % operators test whether the left hand  element
  822. contains  the  right  hand  element.  For example, NAME $
  823. "Bee" is true for the Beethoven record but false for  the
  824. other  composers.   The  %  operator returns the opposite
  825. result.
  826.  
  827. The default table name in the where clause  is  inherited
  828. from  the  qfn  list but is changed each time a qualified
  829. field name is encountered.
  830.  
  831. Fields from different  tables  may  appear  in  the  same
  832. comparison.   If  qfn's  from different tables are in the
  833. display list, it is likely there will  be  at  least  one
  834. cross-table  comparison.  For example, Figure 5-2 shows a
  835. join of composers (COMP) with their works (OPUS).
  836.  
  837.  
  838.  
  839.  
  840.  
  841.                           5-13
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.                     COMMAND REFERENCE
  862.                          SELECT
  863.  
  864.  
  865.  
  866.       SELECT COMP.ALL OPUS.WORK WHERE COMPOSER=COMP.NAME
  867.  
  868.  
  869. NAME                 BORN  DIED  COUNTRY   WORK                       
  870.  
  871. Brahms, J.           1833  1897  Germany   Lullaby           
  872. Beethoven, L.        1770  1827  Germany   Symphony No. 5
  873.  
  874. Figure 5-2.  Using select for a join.
  875.  
  876. The 11 records in COMP are paired with the 2 in OPUS  for
  877. 22  possible  combinations.   Of  those  22, only the two
  878. which   have   identical   values   of   COMP.NAME    and
  879. OPUS.COMPOSER  are displayed.  (This conceptual execution
  880. of a join is not necessarily how PC-DBMS implements it.)
  881.  
  882. PC-DBMS permits up to ten comparisons to be used,  linked
  883. together by ANDs and ORs.  For example, to find composers
  884. who lived entirely in the nineteenth century, use
  885.  
  886.      SELECT COMP.ALL WHE BORN>1799 AND DIED<1900
  887.  
  888. The complement to this set of composers  is  the  set  of
  889. composers  not  alive  at  any time during the nineteenth
  890. century.  One way to find them  is  with  the  complement
  891. operator, NOT.  For example,
  892.  
  893.      SELECT COMP.ALL WHE NOT ( BORN>1799 AND DIED<1900 )
  894.  
  895. NOT makes anything that is true false and vice versa.  It
  896. is  typically  used  on  a  combination of comparisons as
  897. above because the individual comparisons have  their  own
  898. complements.   For  example,  NOT  NAME>"Smith"  is  just
  899. NAME<= "Smith".  Space between NOT and ( is optional.
  900.  
  901. Parentheses, nested to any desired depth, can be used  to
  902. alter  the order of evaluation of a where clause.  In the
  903. preceding comparison, parentheses  assure  that  the  two
  904. comparisons  are  evaluated  and  combined  and then that
  905. result is negated.
  906.  
  907.                           5-14
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.                     COMMAND REFERENCE
  928.                          SELECT
  929.  
  930.  
  931. Like algebra, there is an order of  evaluation  in  where
  932. clauses.   Comparisons  are evaluated (to true and false)
  933. first.  Then NOTs are applied.  AND comes next and OR  is
  934. last.
  935.  
  936. A table may be referenced  for  the  first  time  in  the
  937. command in the where clause.
  938.  
  939. The sorted by clause is also  optional.   It  contains  a
  940. list  of  one  to five field names from tables referenced
  941. earlier in the command.  The  first  field  name  is  the
  942. major  sort  key  and  the  last  is  the minor sort key.
  943. Filler fields may not be used.
  944.  
  945. The default sorting order is ascending (aardvarks  before
  946. zebras).   To  get  descending  order on a key, follow it
  947. with "\d" or "\D".  Use "\a" or  "\A"  to  get  ascending
  948. order, the default.
  949.  
  950. For example, Figure 5-3 shows retrieval of  composers  in
  951. reverse  order of birth and breaks ties (Bach and Handel)
  952. by alphabetizing their names.
  953.  
  954.         SEL COMP.ALL SOR BY BORN\D NAME
  955.  
  956.  
  957. NAME                 BORN  DIED  COUNTRY          
  958.  
  959. Debussy, C.          1862  1918  France         
  960. Tchaikovsky, P.      1840  1893  Russia         
  961. Brahms, J.           1833  1897  Germany        
  962. Verdi, G.            1813  1901  Italy          
  963. Chopin, F.           1810  1849  France         
  964. Mendelssohn, F.      1809  1847  Germany        
  965. Beethoven, L.        1770  1827  Germany        
  966. Mozart, W.           1756  1791  Austria        
  967. Haydn, F.            1732  1809  Austria        
  968. Bach, J.             1685  1750  Germany        
  969. Handel, G.           1685  1759  England        
  970.  
  971. Figure 5-3.  A select command with sorting.
  972.  
  973.                           5-15
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.                     COMMAND REFERENCE
  994.                          SELECT
  995.  
  996.  
  997. The select command will abort with an  error  message  if
  998. the  output  string  is  too  wide.   The  output  string
  999. contains the fields  to  be  displayed  plus  two  spaces
  1000. between  adjacent  fields.   Spaces are suppressed if the
  1001. into clause is present.  Add to the output  string  width
  1002. the  width  of  the  widest  sort field.  The sum may not
  1003. exceed 141.
  1004.  
  1005. The optional  into  clause  comes  last.   It  makes  the
  1006. retrieved  table  part  of  the  data base by writing the
  1007. output to a file and making appropriate  entries  in  the
  1008. schema.  Only an information message will be displayed on
  1009. screen.
  1010.  
  1011. Into is followed by the name for  the  new  table.   That
  1012. name  follows  the  conventions for naming tables but may
  1013. not exceed eight characters.  The name may not already be
  1014. in use as a table name.  The file for the table will have
  1015. the table's  name  as  its  file  name  and  DAT  as  its
  1016. extension.   It  will  be in the current directory of the
  1017. logged drive.  No drive will be recorded for  it  in  the
  1018. schema.  The new table will have no indices.
  1019.  
  1020. No more than two tables can be referenced  prior  to  the
  1021. into clause.
  1022.  
  1023. An example of  a  complex  select  command  follows.   It
  1024. illustrates simultaneous use of all the clauses.
  1025.  
  1026.         SELECT COMP.COUNTRY COMP.BORN OPUS.ALL
  1027.          WHERE COMPOSER=COMP.NAME 
  1028.          AND NOT (DIED<1900 AND BORN>1799)
  1029.          SORT BY NAME BORN\D
  1030.          INTO NU_TABLE
  1031.  
  1032. During output, scrolling can be suspended by pressing the
  1033. control-num lock or control-S key and resumed by pressing
  1034. any other key.  The F10 key aborts output.
  1035.  
  1036.  
  1037.  
  1038.  
  1039.                           5-16
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.                     COMMAND REFERENCE
  1060.                          SELECT
  1061.  
  1062.  
  1063. Skeletal select commands can be composed easily with  the
  1064. DISPLAY\QUERY command.
  1065.  
  1066.  
  1067.  
  1068. SHOW
  1069.  
  1070. The show command displays a portion of the  schema.   The
  1071. syntax is:
  1072.  
  1073.      SHOW [\FIELDS] [\DESCRIBE] [table_name ...]
  1074.  
  1075. The optional qualifiers \FIELDS and  \DESCRIBE  determine
  1076. what  kind  of  information is retrieved from the schema.
  1077. It is possible to use zero, one or two qualifiers.   Note
  1078. that   SHOW\FIELDS\DESCRIBE   has   the  same  effect  as
  1079. SHOW\DESCRIBE\FIELDS.
  1080.  
  1081. The FIELDS  qualifier  displays  information  on  fields.
  1082. Without   this   qualifier,   information  on  tables  is
  1083. retrieved.   The  DESCRIBE  qualifier  retrieves   verbal
  1084. descriptions.     Without    this    qualifier,   tabular
  1085. information is retrieved.
  1086.  
  1087. If one or more tables is named, only information on those
  1088. tables  is  retrieved.   Otherwise, data on all tables is
  1089. shown.
  1090.  
  1091. Four   examples   follow.    They   show   all   possible
  1092. combinations  of  the  qualifiers  (one, the other, both,
  1093. neither).  For brevity, schema information  is  retrieved
  1094. for only one table.
  1095.  
  1096. The unqualified show command produces tabular information
  1097. on one or more tables.  See Figure 5-4.
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.                           5-17
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.                     COMMAND REFERENCE
  1126.                           SHOW
  1127.  
  1128.  
  1129.  
  1130.         SHOW COMP  'info on table COMP
  1131.  
  1132. TABLE NAME  FILE           RECORDS FIELDS  EOR  MODIFIED
  1133.  
  1134. COMP        COMPOSER.DAT        11      6    2   01-11-85
  1135.  
  1136. Figure 5-4.  The show command without qualifiers.
  1137.  
  1138. The output exhibits the number  of  records  and  fields.
  1139. EOR  gives  the  end  of  record  terminator;  0 means no
  1140. terminator, 1 means carriage return and 2 means  carriage
  1141. return-line feed.
  1142.  
  1143. With just the DESCRIBE qualifier, show displays a  verbal
  1144. description of one or more tables.  See Figure 5-5.
  1145.  
  1146.         SHO\DESCRIBE COMP  'description of table COMP
  1147.  
  1148.    TABLE NAME          DESCRIPTION
  1149.  
  1150. COMP             information about some composers
  1151.  
  1152. Figure 5-5.  The show\describe command.
  1153.  
  1154. With just the FIELDS  qualifier,  show  displays  tabular
  1155. information  about the fields of one or more tables.  See
  1156. Figure 5-6.
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.                           5-18
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.                     COMMAND REFERENCE
  1192.                           SHOW
  1193.  
  1194.  
  1195.  
  1196.         SHO\FIELDS COMP  'info on fields in table COMP
  1197.  
  1198.    FIELD NAME   TYPE KEY FROM    TO
  1199.  
  1200.  
  1201. TABLE   COMP            
  1202.  
  1203. NAME              T   N     1    19
  1204. BORN              N   N    20    23
  1205. filler1           F   N    24    24
  1206. DIED              N   N    25    28
  1207. filler2           F   N    29    29
  1208. COUNTRY           T   N    30    44
  1209.  
  1210. Figure 5-6.  The show\fields command.
  1211.  
  1212. The TYPE column indicates the field's data type:   T  for
  1213. text,  N  for numeric and F for filler.  KEY indicates if
  1214. the field is indexed:  Y for yes and N for no.  The  FROM
  1215. and  TO  columns  show  each  field's starting and ending
  1216. positions in the data file.
  1217.  
  1218. Show with both qualifiers (either order) exhibits  verbal
  1219. descriptions  of  the  fields of one or more tables.  See
  1220. Figure 5-7.
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.                           5-19
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.                     COMMAND REFERENCE
  1258.                           SHOW
  1259.  
  1260.  
  1261.  
  1262.         SHO\FIE\DES COMP  'descriptions of fields in COMP
  1263.  
  1264.   FIELD NAME         DESCRIPTION
  1265.  
  1266.  
  1267. TABLE   COMP            
  1268.  
  1269. NAME          the composer's last name and first initial
  1270. BORN          the year the composer was born   
  1271. filler1                         
  1272. DIED          the year of the composer's death 
  1273. filler2                               
  1274. COUNTRY       the composer's country of residence  
  1275.  
  1276. Figure 5-7.  The show\fie\des command.
  1277.  
  1278. During output, scrolling can be suspended by pressing the
  1279. control-num lock or control-S key and resumed by pressing
  1280. any other key.  The F10 key aborts output.
  1281.  
  1282.  
  1283.  
  1284. TOLERANCE
  1285.  
  1286. The tolerance command sets the comparison tolerance  used
  1287. in  processing  where clauses.  It affects only numerical
  1288. comparisons.  The syntax is
  1289.  
  1290.      TOLERANCE number
  1291.  
  1292. The tolerance is set to the  absolute  value  of  number.
  1293. The  default  value  is zero, i.e., the value before this
  1294. command is first given.
  1295.  
  1296. Slight conversion  errors  occur  in  converting  between
  1297. decimal  (used  by people and stored in files) and binary
  1298. (used internally by PC-DBMS) because the machine does not
  1299. have  infinite precision.  Non-zero tolerance circumvents
  1300. these errors.
  1301.  
  1302.  
  1303.                           5-20
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.                     COMMAND REFERENCE
  1324.                         TOLERANCE
  1325.  
  1326.  
  1327. The range  created  by  tolerance  can  be  exploited  to
  1328. simplify  queries.   For  example,  with  zero tolerance,
  1329. certain records are qualified by
  1330.  
  1331.      WHERE YEAR>=1895 AND YEAR<=1905
  1332.  
  1333. If tolerance is set to 5, the same records will, ignoring
  1334. conversion errors, be qualified by
  1335.  
  1336.      WHERE YEAR=1900
  1337.  
  1338. Here are the formal tolerance rules.  If  F  is  a  field
  1339. with  value  a and r is another field or a user specified
  1340. number and t is the tolerance,  then  the  following  are
  1341. true conditions.
  1342.  
  1343.         F =  r if and only if r-t <= a <= r+t
  1344.         F <> r if and only if a < r-t or a > r+t
  1345.         F >  r if and only if a > r-t
  1346.         F >= r if and only if a >= r-t
  1347.         F <  r if and only if a < r+t
  1348.         F <= r if and only if a <= r+t
  1349.  
  1350. If NOT precedes a where clause condition, the operator of
  1351. the  condition  will  be complemented and the NOT removed
  1352. when the condition is processed.  For example, NOT YEAR >
  1353. 1900  is  processed  as YEAR <= 1900.  If tolerance is 2,
  1354. then records  with  YEAR  greater  than  1898  should  be
  1355. excluded.   In fact, records with YEAR less than or equal
  1356. to 1902 will be included.
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.                           5-21
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.                        APPENDIX A
  1402.  
  1403.                         KEYWORDS
  1404.  
  1405.  
  1406.  
  1407. PC-DBMS keywords  can  be  truncated  to  three  or  more
  1408. characters  and  entered  in  upper, lower or mixed case.
  1409. The keywords and their truncations should not be used for
  1410. names  of  data  bases,  tables  or  fields.   A  list of
  1411. keywords is in Table A-1.
  1412.  
  1413.  
  1414.  
  1415. ALL                INTO
  1416. ALLF               KEY
  1417. AND                OPEN
  1418. BY                 OR
  1419. DEFINE             OUTPUT
  1420. DEKEY              QUERY
  1421. DESCRIBE           REMOVE
  1422. DISPLAY            SELECT
  1423. EDIT               SHOW
  1424. EXIT               SORTED
  1425. FIELDS             TOLERANCE
  1426. INPUT              WHERE
  1427.  
  1428. Table A-1.  The keywords of PC-DBMS.
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.                            A-1
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.                        APPENDIX B
  1468.  
  1469.                   THE RELATIONAL MODEL
  1470.  
  1471.  
  1472.  
  1473. PC-DBMS is a data base management system which implements
  1474. the  relational  model of data management.  This appendix
  1475. describes the relational model and  how  to  design  data
  1476. bases around it.
  1477.  
  1478. Relational data bases contain  data  tables.   These  are
  1479. familiar  objects;   they  have  rows  called records and
  1480. columns called fields.
  1481.  
  1482. Data bases typically have more than  one  table.   For  a
  1483. given  information  content,  a data base might have one,
  1484. two, three  or  more  tables.   How  many  tables  should
  1485. contain  that  information?   Which  fields should be put
  1486. into which tables?  The purpose of this  appendix  is  to
  1487. help you answer those questions, i.e., to help you design
  1488. your  data  base.   If  you're  still  looking  for  more
  1489. information  when  you  finish,  you might consult C.  J.
  1490. Date, "An Introduction to  Database  Systems,"  (Reading,
  1491. Massachusetts:  Addison-Wesley Publishing Co., 1976).
  1492.  
  1493. We will progress through several data bases, each  better
  1494. organized than the last.
  1495.  
  1496. First, consider the one table data base in Figure B-1.
  1497.  
  1498.  
  1499.  
  1500.  
  1501.                            B-1
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.                   THE RELATIONAL MODEL
  1522.  
  1523.  
  1524.  
  1525.  
  1526. NAME_1   SSNO_1        NAME_2   SSNO_2
  1527.  
  1528. Jack     123-45-6789   Mary     987-65-4321
  1529.  
  1530. Figure B-1.  A table with repeating fields.
  1531.  
  1532. There are four fields and one record.  It is obvious that
  1533. the fields repeat;  the second pair of fields contain the
  1534. same sort of information as the first pair.  This kind of
  1535. table is called unnormalized.
  1536.  
  1537. Suppose we have to find Mary's  Social  Security  number.
  1538. We  would  have to search the NAME_1 field and the NAME_2
  1539. field for "Mary".  She might be in either one.  This is a
  1540. difficult  query.   More  difficult still is a join, that
  1541. is, connecting the records in this table with the records
  1542. in  another  table  on  the  basis of a common field like
  1543. Social  Security  number.   Each  record  has  two   such
  1544. numbers.  Which one should be used?
  1545.  
  1546. Unnormalized tables can be normalized simply.  Just  make
  1547. additional  records  of the repeating fields as in Figure
  1548. B-2.
  1549.  
  1550. NAME   SSNO
  1551.  
  1552. Jack   123-45-6789
  1553. Mary   987-65-4321
  1554.  
  1555. Figure B-2.  A normalized table.
  1556.  
  1557. Normalized tables are said to be  in  first  normal  form
  1558. (1NF).
  1559.  
  1560. Let's define a concept known as  the  primary  key  of  a
  1561. table.   The  primary  key  is  a field or combination of
  1562. fields which, when their values are  specified,  uniquely
  1563. identifies  no  more  than one record.  For example, in a
  1564. table with the two  fields  SSNO  and  BIRTH_PLACE,  SSNO
  1565. would  be  the primary key because for each listed Social
  1566.  
  1567.                            B-2
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.                   THE RELATIONAL MODEL
  1588.  
  1589.  
  1590.  
  1591. Security  number  there  is   only   one   birth   place.
  1592. BIRTH_PLACE cannot be the primary key because for a given
  1593. BIRTH_PLACE there may be  many  Social  Security  numbers
  1594. (people).
  1595.  
  1596. If a table has a primary key, its records are unique.
  1597.  
  1598. It may take several fields to  comprise  a  primary  key.
  1599. For  example,  in  a table which gives different people's
  1600. incomes for different years, there are the  fields  SSNO,
  1601. YEAR  and  INCOME.   The  first two uniquely identify the
  1602. record;  they are the primary key.
  1603.  
  1604. Let's append a fourth field to this two field primary key
  1605. table  to  study  second normal form (2NF).  The table is
  1606. already in 1NF because its records do not  contain  lists
  1607. or repeating fields.  See Figure B-3.
  1608.  
  1609. SSNO         YEAR  INCOME  NAME
  1610.  
  1611. 123-45-6789  1980   15000  Jack
  1612. 987-65-4321  1980   22000  Mary
  1613. 123-45-6789  1981   16500  Jack
  1614. 987-65-4321  1981   24000  Mary
  1615.  
  1616. Figure B-3.  A table not in 2NF.
  1617.  
  1618. Once both SSNO and YEAR are specified, the record can  be
  1619. identified  and  the other two fields looked up.  Neither
  1620. field in the primary key is sufficient to identify INCOME
  1621. uniquely.   For  example,  YEAR  =  1980  identifies  two
  1622. records.   The  entire  primary  key,  both  fields,   is
  1623. necessary to identify INCOME.
  1624.  
  1625. However, once SSNO is known, NAME can  be  looked  up  in
  1626. Figure  B-3.   That is, NAME depends on less than all the
  1627. fields in the primary key.  In relational jargon,  INCOME
  1628. is  fully  functionally  dependent on the primary key but
  1629. NAME is only functionally dependent.
  1630.  
  1631.  
  1632.  
  1633.                            B-3
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.                   THE RELATIONAL MODEL
  1654.  
  1655.  
  1656.  
  1657. If all the non-key  fields  in  a  1NF  table  are  fully
  1658. functionally  dependent  on the primary key, the table is
  1659. in 2NF.  Why should we care?
  1660.  
  1661. Data base corruption is one reason we should  care.   For
  1662. example,   suppose  in  entering  "Mary"  twice,  it  was
  1663. misspelled once as "Marie".  Then,  one  Social  Security
  1664. number  would  correspond  to  two NAMEs.  Note that full
  1665. functional dependency implies only one value per  non-key
  1666. field  (INCOME)  for  each  primary key value.  Incorrect
  1667. replicates (Mary and Marie) cannot exist because multiple
  1668. entries   per   primary   key   are   precluded.   Hence,
  1669. consistency or integrity is one reason for 2NF.
  1670.  
  1671. There are other reasons for preferring 2NF but  let's  go
  1672. on  to  correct  the  problem.  Split one table into two.
  1673. See Figure B-4.
  1674.  
  1675. SSNO         YEAR  INCOME               SSNO         NAME
  1676.                                
  1677. 123-45-6789  1980   15000               123-45-6789  Jack
  1678. 987-65-4321  1980   22000               987-65-4321  Mary
  1679. 123-45-6789  1981   16500  
  1680. 987-65-4321  1981   24000  
  1681.  
  1682. Figure B-4.  Tables in 2NF.
  1683.  
  1684. Both tables are in 2NF.  In the left table, SSNO and YEAR
  1685. are  the  primary  key  and  INCOME is fully functionally
  1686. dependent on them.   In  the  right  table  SSNO  is  the
  1687. primary  key  and  NAME  is  the  non-key field (but full
  1688. functional dependency is immaterial because  of  the  one
  1689. field primary key).
  1690.  
  1691. Note that in the two table version of the data  base,  we
  1692. can  record  Fred's  Social Security number (right table)
  1693. although there isn't enough information to make an  entry
  1694. for him in the left table.  This capability did not exist
  1695. in the single table (1NF) version.
  1696.  
  1697.  
  1698.  
  1699.                            B-4
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.                   THE RELATIONAL MODEL
  1720.  
  1721.  
  1722.  
  1723. The table in Figure B-5  is  in  2NF  but  it  still  has
  1724. problems.
  1725.  
  1726. SSNO         AGE  HOME_TOWN  AVG_TEMP
  1727.  
  1728. 123-45-6789   32  Boston           53
  1729. 987-65-4321   19  Dallas           59
  1730. 369-47-5814   50  El Paso          59
  1731. 421-63-9631   41  Boston           47
  1732.  
  1733. Figure B-5.  A table not in 3NF.
  1734.  
  1735. SSNO is the primary  key  of  this  table.   The  non-key
  1736. fields,  AGE,  HOME_TOWN  and  AVG_TEMP, are functionally
  1737. dependent  on  the  primary   key.    (They   are   fully
  1738. functionally  dependent,  too,  but this is trivial for a
  1739. one field primary key.)
  1740.  
  1741. Observe that Boston has two average temperatures and they
  1742. are  different.   True,  this  illustrates  a  data entry
  1743. error.  However, it is possible to structure a data  base
  1744. to  guard  against such errors.  That's what third normal
  1745. form (3NF) is for.
  1746.  
  1747. In Figure B-5, there is a functional  dependency  between
  1748. non-key  fields.   That  is,  AVG_TEMP  is  dependent  on
  1749. HOME_TOWN.  Once HOME_TOWN is known, an uncorrupted  data
  1750. base  would  tell  us AVG_TEMP.  Dependency among non-key
  1751. fields is permissible in 2NF but not in 3NF.
  1752.  
  1753. The remedy, as before, is to split one  table  into  two.
  1754. See Figure B-6.
  1755.  
  1756. SSNO         AGE  HOME_TOWN           HOME_TOWN  AVG_TEMP
  1757.  
  1758. 123-45-6789   32  Boston              Boston           53
  1759. 987-65-4321   19  Dallas              Dallas           59
  1760. 369-47-5814   50  El Paso             El Paso          59
  1761. 421-63-9631   41  Boston
  1762.  
  1763. Figure B-6.  Tables in 3NF.
  1764.  
  1765.                            B-5
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.                   THE RELATIONAL MODEL
  1786.  
  1787.  
  1788.  
  1789. In each new table of Figure B-6, the left  field  is  the
  1790. primary  key.   In the left table, the two non-key fields
  1791. are mutually  independent  --  knowing  either  does  not
  1792. identify  the  other.   Hence,  the left table is in 3NF.
  1793. There is only one non-key field in the right table so 2NF
  1794. implies 3NF.
  1795.  
  1796. Aside from avoiding the corruption  encountered  earlier,
  1797. it  is  also  possible  to  record  the  AVG_TEMP  for  a
  1798. HOME_TOWN even if we don't know the SSNO  of  anyone  who
  1799. lives  there.  That is, we can have a record in the right
  1800. table  without  a  correspondent  in  the   left   table.
  1801. Similarly, we can have a record in the left table even if
  1802. we don't know the AVG_TEMP of that person's HOME_TOWN.
  1803.  
  1804. To sum up, a table in  1NF  has  no  lists  or  repeating
  1805. fields  in  its  records.   A 2NF table is a 1NF table in
  1806. which each non-key field is fully functionally  dependent
  1807. on the entire primary key.  Finally, a 3NF table is a 2NF
  1808. table  in  which  the   non-key   fields   are   mutually
  1809. independent.
  1810.  
  1811. A data  base  consisting  of  third  normal  form  tables
  1812. provides the most protection against corruption.  It also
  1813. permits tables to  be  modified  individually,  e.g.,  we
  1814. don't have to know the age and Social Security of someone
  1815. in Detroit to enter that city's  average  temperature  in
  1816. Figure B-6.
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.                            B-6
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.                        APPENDIX C
  1864.  
  1865.                  USER SUPPORTED SOFTWARE
  1866.  
  1867.  
  1868.  
  1869. PC-DBMS is distributed as user supported  software.   You
  1870. are   encouraged  to  make  copies  of  the  distribution
  1871. diskette for other potential users.  There is no  license
  1872. agreement   but  please  pass  along  all  files  without
  1873. modification.  User groups and similar organizations  may
  1874. impose a nominal charge to cover the cost of duplication.
  1875.  
  1876. The user supported concept of software is  a  significant
  1877. innovation  (not  mine)  which  benefits  both  user  and
  1878. author.  For  the  user,  there  is  the  convenience  of
  1879. leisurely evaluation of the program on your own system in
  1880. your own home or office to see if  it's  right  for  your
  1881. application.   The  low  cost  of user supported software
  1882. distribution also  makes  possible  a  voluntary  payment
  1883. lower  than  the  price  of commercial software.  And, of
  1884. course,  there's  no  copy  protection  to  diminish  the
  1885. utility of the program.
  1886.  
  1887. For the author, there is the satisfaction  of  getting  a
  1888. far  larger  number  of  copies into use than is possible
  1889. with conventional marketing.  Also, the  interference  of
  1890. piracy is turned into a reinforcement in the distribution
  1891. of the program.   Finally,  if  you  have  dealt  with  a
  1892. publisher,   print  or  electronic,  you  understand  the
  1893. undesirability of that alternative.
  1894.  
  1895.  
  1896.  
  1897.                            C-1
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.                  USER SUPPORTED SOFTWARE
  1918.  
  1919.  
  1920.  
  1921. However, it doesn't work unless you want it to.   If  you
  1922. find  PC-DBMS  useful,  I hope you will see fit to make a
  1923. voluntary payment of $60, by check or through  your  bank
  1924. credit  card.  Beyond what you already have, this is what
  1925. you will receive from me.
  1926.  
  1927.       -  A typeset, bound edition of the User's Guide.
  1928.  
  1929.       -  A mailed copy of the  next  version  of  PC-DBMS
  1930.          without charge.
  1931.  
  1932.       -  Support.  Comments, suggestions  and  especially
  1933.          bug  reports  are welcome from anyone.  However,
  1934.          only users who have made a voluntary payment can
  1935.          expect replies to their questions.  Support will
  1936.          be provided on a best efforts basis by mail  and
  1937.          through   Compuserve.    My   Compuserve  id  is
  1938.          74216,3033.
  1939.  
  1940.       -  My thanks.  PC-DBMS took a year to develop, test
  1941.          and document.  I enjoyed every minute of it.
  1942.  
  1943.  
  1944. Now, I ask that you send your voluntary payment with  the
  1945. registration  form.   A  copy of that form is on the next
  1946. page or, if you wish to leave your manual intact, another
  1947. copy is in the file REQUEST.DOC.  If you need an invoice,
  1948. you'll find one following the registration form  in  both
  1949. the manual and in REQUEST.DOC.
  1950.  
  1951. For quantity purchases of PC-DBMS, contact Kware.
  1952.  
  1953. Thank you.
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.                            C-2
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.                 PC-DBMS REGISTRATION FORM
  1984.                          
  1985.  
  1986. Name    _____________________________  Phone ____________
  1987.  
  1988. Company _____________________________
  1989.  
  1990. Address _____________________________
  1991.         
  1992.         _____________________________
  1993.  
  1994. City    _____________________________  
  1995.  
  1996. State   ______________ Zip __________
  1997.  
  1998. version number  ___________
  1999.  
  2000.  
  2001. source of your copy (club or bulletin board),
  2002.  
  2003.   if known  _____________________________________________
  2004.  
  2005.  
  2006. To use a credit card, please indicate:
  2007.  
  2008.   Visa  __   or Mastercard __     
  2009.  
  2010.   card number  ____________________________
  2011.  
  2012.   expiration month/year  ______/________
  2013.  
  2014.   signature  ______________________________
  2015.  
  2016.  
  2017. To pay by check, please make payable to Kware for $60.  
  2018.   Virginia residents add 4% sales tax.
  2019.  
  2020.  
  2021. Kware                               Thank you.
  2022. P. O. Box 16206
  2023. Arlington, Va. 22215                  Paul Kobrin
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.                            C-3
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.                        INVOICE
  2052.        
  2053.  
  2054. Vendor:  Kware, Inc.              Federal EIN: 54-1304150
  2055.          P. O. Box 16206
  2056.          Arlington, Va. 22215     Date:    /    /
  2057.  
  2058.  
  2059. Description        Qty      Price       Extension
  2060. -----------        ---      -----       ---------
  2061.  
  2062. PC-DBMS,             1      $60.00         $60.00
  2063.  User's Guide,
  2064.  support
  2065.                                         --------- 
  2066.                    Sub-total                60.00
  2067.  
  2068. Tax @ 4% for Va. residents ($2.40)
  2069.  
  2070.                                         ---------
  2071.                    Amount due
  2072.  
  2073.  
  2074.  
  2075. You may retain this invoice.
  2076. Please make check payable to Kware.
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.                            C-4
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.                           INDEX
  2116.  
  2117.  
  2118.  
  2119.  
  2120. All
  2121.   keyword  . . . . . . . . . 3-5, 5-5, 5-11
  2122. Allf
  2123.   keyword  . . . . . . . . . 5-11
  2124. Alphabetize  . . . . . . . . 3-6, 5-15
  2125. And
  2126.   keyword  . . . . . . . . . 3-6, 5-5, 5-12, 5-14 to 5-15
  2127. Apostrophe
  2128.   comment delimiter  . . . . 4-5
  2129. Ascii  . . . . . . . . . . . 4-2, 5-13
  2130.  
  2131. Backslash
  2132.   in deleted records . . . . 4-2, 5-3
  2133. Backspace key  . . . . . . . 3-4, 3-6, 3-13, 4-4
  2134. Blank padding  . . . . . . . 5-13
  2135. Brackets . . . . . . . . . . 5-2
  2136.  
  2137. Carriage return  . . . . . . 3-4, 4-4
  2138. Case
  2139.   sensitivity  . . . . . . . 4-3, 5-2, A-1
  2140. Character string . . . . . . 4-5
  2141.   see also text string
  2142. Close command  . . . . . . . 5-9
  2143. Color  . . . . . . . . . . . 2-1, 3-2
  2144. Command window . . . . . . . 3-4, 4-3, 4-5, 5-6
  2145. Comments
  2146.   in commands  . . . . . . . 4-5
  2147. Comparison . . . . . . . . . 5-12 to 5-14, 5-20
  2148.   see also condition
  2149. Compuserve . . . . . . . . . C-2
  2150. Condition  . . . . . . . . . 3-5, 5-12, 5-21
  2151.   see also comparison
  2152. Continuation character . . . 4-4
  2153. Control-num lock . . . . . . 5-16, 5-20
  2154. Control-s  . . . . . . . . . 3-7, 3-9, 5-16, 5-20
  2155. Cursor keys  . . . . . . . . 3-4, 3-11, 3-13, 4-4
  2156.  
  2157. Data dictionary  . . . . . . 3-10
  2158.   see also schema
  2159. Default table  . . . . . . . 3-7 to 3-8, 5-7, 5-11, 5-13
  2160.  
  2161.                          Index-1
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181. Define command . . . . . . . 3-12, 5-2
  2182. Define utility . . . . . . . 3-12, 3-15, 4-2, 5-2
  2183. Dekey command  . . . . . . . 3-15 to 3-16, 5-4
  2184. Delete key . . . . . . . . . 3-6, 4-4
  2185. Directory  . . . . . . . . . 4-1, 5-16
  2186.   see also subdirectory
  2187. Display command  . . . . . . 3-10, 5-4, 5-7, 5-9
  2188. Display utility  . . . . . . 3-10 to 3-11, 3-15, 4-3, 
  2189.                              5-3, 5-5 to 5-8
  2190. Distribution diskette  . . . 2-1
  2191. Dos  . . . . . . . . . . . . 2-1, 2-3, 3-2, 3-16, 5-3
  2192. Drive names  . . . . . . . . 5-3
  2193.  
  2194. Editor . . . . . . . . . . . 4-3, 5-8
  2195. Ellipses . . . . . . . . . . 5-2
  2196. End key  . . . . . . . . . . 4-4
  2197. Errors
  2198.   see messages
  2199. Exit command . . . . . . . . 3-16, 4-5, 5-8
  2200. Export
  2201.   data . . . . . . . . . . . 4-2
  2202.  
  2203. F1 key . . . . . . . . . . . 3-3, 3-11, 4-5, 5-8
  2204. F10 key  . . . . . . . . . . 3-7, 3-11 to 3-12, 
  2205.                              3-15 to 3-16, 4-5, 5-3, 
  2206.                              5-5 to 5-7, 5-16, 5-20
  2207. F2 key . . . . . . . . . . . 4-6
  2208. F3 key . . . . . . . . . . . 3-4, 4-5
  2209. F4 key . . . . . . . . . . . 3-12, 5-6
  2210. F6 key . . . . . . . . . . . 3-12, 5-6
  2211. F7 key . . . . . . . . . . . 3-4, 3-11 to 3-12, 4-5, 
  2212.                              5-5 to 5-6
  2213. F9 key . . . . . . . . . . . 3-11, 4-5, 5-8
  2214. Field block  . . . . . . . . 3-10 to 3-11, 4-3, 5-4, 5-8
  2215. Fields
  2216.   filler . . . . . . . . . . 3-9, 5-3, 5-13, 5-15
  2217.   functionally dependent . . B-3 to B-6
  2218.   numeric  . . . . . . . . . 3-9, 5-3
  2219.   text . . . . . . . . . . . 3-9, 5-3
  2220. File specifications  . . . . 5-3
  2221. Files
  2222.   character positions in . . 3-9
  2223.   data . . . . . . . . . . . 4-1 to 4-2, 5-2, 5-16, 5-19
  2224.   def  . . . . . . . . . . . 4-1
  2225.   distribution . . . . . . . 2-1, C-1
  2226.  
  2227.                          Index-2
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.   idx  . . . . . . . . . . . 4-1
  2248.   index  . . . . . . . . . . 4-1, 5-4, 5-8, 5-10
  2249.   maintenance  . . . . . . . 3-15
  2250.   schema . . . . . . . . . . 4-1 to 4-2, 5-9
  2251. Flying reform
  2252.   editor . . . . . . . . . . 4-3 to 4-4
  2253. Functionally dependent
  2254.   see fields
  2255.  
  2256. Help . . . . . . . . . . . . 3-3, 3-11, 4-5 to 4-6, 5-8
  2257. Help menu  . . . . . . . . . 3-3
  2258. Home key . . . . . . . . . . 4-4
  2259.  
  2260. Import
  2261.   data . . . . . . . . . . . 4-2, 5-3
  2262. Index  . . . . . . . . . . . 3-15 to 3-16, 5-4, 
  2263.                              5-8 to 5-9, 5-16
  2264.   see also key
  2265. Insert mode
  2266.   editor . . . . . . . . . . 4-3
  2267. Installation . . . . . . . . 2-2
  2268. Into clause  . . . . . . . . 3-7 to 3-8, 3-15, 5-10, 5-16
  2269. Invoice  . . . . . . . . . . C-4
  2270.  
  2271. Join
  2272.   relational operation . . . 3-7 to 3-8, 3-16, 
  2273.                              5-13 to 5-14, B-2
  2274.  
  2275. Key  . . . . . . . . . . . . 3-15 to 3-16, 5-19
  2276.   see also index
  2277. Key command  . . . . . . . . 3-15, 5-8
  2278. Keyword  . . . . . . . . . . 4-3, A-1
  2279.   see also truncation
  2280.  
  2281. Main screen  . . . . . . . . 3-2, 3-11 to 3-13, 3-15, 
  2282.                              4-3, 4-5, 5-5 to 5-6
  2283. Menu
  2284.   see help menu
  2285. Message window . . . . . . . 3-4
  2286. Messages
  2287.   error or warning . . . . . 3-4, 4-5
  2288.  
  2289. Names
  2290.   data base  . . . . . . . . 4-3, A-1
  2291.   field  . . . . . . . . . . 4-3, A-1
  2292.  
  2293.                          Index-3
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.   qualified field  . . . . . 3-7, 4-3, 5-4, 5-9, 5-11, 
  2314.                              5-13
  2315.   table  . . . . . . . . . . 4-3, A-1
  2316.     into clause  . . . . . . 5-16
  2317. Normal form  . . . . . . . . B-2 to B-3, B-5 to B-6
  2318. Not
  2319.   keyword  . . . . . . . . . 5-14 to 5-15, 5-21
  2320. Numbers
  2321.   representation . . . . . . 4-4
  2322.  
  2323. Open command . . . . . . . . 3-4, 5-9
  2324. Or
  2325.   keyword  . . . . . . . . . 3-6, 5-12, 5-14 to 5-15
  2326. Output command . . . . . . . 5-9 to 5-10
  2327. Output window  . . . . . . . 3-2
  2328.  
  2329. Parentheses  . . . . . . . . 5-14
  2330. Path names . . . . . . . . . 5-3
  2331. Primary key  . . . . . . . . B-2 to B-6
  2332. Printer  . . . . . . . . . . 5-9
  2333.  
  2334. Qualified field names
  2335.   see names
  2336. Quote mark
  2337.   text delimiter . . . . . . 3-6, 4-5, 5-7
  2338.  
  2339. Recall
  2340.   command  . . . . . . . . . 3-8
  2341. Record terminator  . . . . . 5-3, 5-18
  2342. Relational model . . . . . . B-1
  2343. Remove command . . . . . . . 3-10, 4-2, 5-10
  2344. Replace mode
  2345.   editor . . . . . . . . . . 4-3 to 4-4, 5-8
  2346.  
  2347. Schema . . . . . . . . . . . 3-10, 3-12, 4-1 to 4-2, 5-4, 
  2348.                              5-8 to 5-10, 5-16 to 5-17
  2349. Scroll . . . . . . . . . . . 3-6 to 3-7, 3-9, 5-20
  2350. Select command . . . . . . . 3-5, 3-7 to 3-8, 4-3, 5-3, 
  2351.                              5-5, 5-9 to 5-11
  2352. Show command . . . . . . . . 3-8, 3-10, 5-9, 5-17
  2353. Sort clause  . . . . . . . . 3-6, 5-3, 5-15
  2354.   maximum width  . . . . . . 5-16
  2355. Space  . . . . . . . . . . . 4-4, 5-13 to 5-14
  2356. Subdirectory . . . . . . . . 2-3, 3-2
  2357.   see also directory
  2358.  
  2359.                          Index-4
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379. Support  . . . . . . . . . . C-2
  2380.  
  2381. Tab key  . . . . . . . . . . 3-11, 5-8
  2382. Text string  . . . . . . . . 3-6
  2383.   see also character string
  2384. Tolerance command  . . . . . 5-13, 5-20
  2385. Truncation
  2386.   keyword  . . . . . . . . . 3-8, 4-5, 5-2, A-1
  2387.  
  2388. User supported software  . . C-1
  2389.  
  2390. Warnings
  2391.   see messages
  2392. Welcome screen . . . . . . . 3-2
  2393. Where clause . . . . . . . . 3-5 to 3-6, 3-16, 5-3, 5-5, 
  2394.                              5-7, 5-12 to 5-13
  2395.   order of evaluation  . . . 5-15
  2396. Word wrapping
  2397.   editor . . . . . . . . . . 3-4, 4-3
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.                          Index-5
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.